package me.yricky.alia.ui.component

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.material.Slider
import androidx.compose.material.SliderDefaults
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color

/**
 * @author Yricky
 * @date 2022/2/11
 */

@Composable
fun ARGBColorPicker(modifier: Modifier = Modifier,initColor:Color,onColorChange:(Color)->Unit){
    Column(modifier) {
        var color by remember {
            mutableStateOf(initColor)
        }
        Row(verticalAlignment = Alignment.CenterVertically) {
            Text("A")
            Slider(
                color.alpha,
                {
                    color = Color(color.red,color.green,color.blue,it)
                    onColorChange(color)
                },
                colors = SliderDefaults.colors(
                    activeTrackColor = Color.Gray,
                    thumbColor = color
                )
            )
        }
        Row(verticalAlignment = Alignment.CenterVertically) {
            Text("R")
            Slider(
                color.red,
                {
                    color = Color(it,color.green,color.blue,color.alpha)
                    onColorChange(color)
                },
                colors = SliderDefaults.colors(
                    activeTrackColor = Color.Red,
                    thumbColor = color
                )
            )
        }
        Row(verticalAlignment = Alignment.CenterVertically) {
            Text("G")
            Slider(
                color.green,
                {
                    color = Color(color.red,it,color.blue,color.alpha)
                    onColorChange(color)
                },
                colors = SliderDefaults.colors(
                    activeTrackColor = Color.Green,
                    thumbColor = color
                )
            )
        }
        Row(verticalAlignment = Alignment.CenterVertically) {
            Text("B")
            Slider(
                color.blue,
                {
                    color = Color(color.red,color.green,it,color.alpha)
                    onColorChange(color)
                },
                colors = SliderDefaults.colors(
                    activeTrackColor = Color.Blue,
                    thumbColor = color
                )
            )
        }
    }
}